package com.jeespring.admin.controller;

import com.github.pagehelper.PageInfo;
import com.jeespring.common.pojo.Page;
import com.jeespring.admin.entity.User;
import com.jeespring.admin.service.UserService;
import com.jeespring.common.pojo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @title:
 * @description:
 * @author: 张朝阳
 * @date: 2019/5/1 00:01
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/page")
    public String page(Model model){
        return "user/user";
    }
    @RequestMapping("/list")
    @ResponseBody
    public Page getUserList(User user , int pageSize, int pageNum){
        PageInfo pageInfo = userService.getUserList(pageNum, pageSize);
        System.out.println("pageSize:" + pageSize);
        System.out.println("pageNumber:" + pageNum);
        Page page = new Page();
        page.setRows(pageInfo.getList());
        page.setTotal(pageInfo.getTotal());
        page.setCode(200);
        return page;
    }

    @RequestMapping("/change/status")
    @ResponseBody
    public Result changeStatus(String id , String status){
        userService.changeStatus(Long.valueOf(id) , Integer.valueOf(status));
        return Result.success();
    }
}
